home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / mesa / mesa-glut / src-glut.aos / glutgetsetcolor.c < prev    next >
C/C++ Source or Header  |  2000-02-23  |  4KB  |  117 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  1.1
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * glutGetSetColor.c
  23.  *
  24.  * Version 1.0  28 Jun 1998
  25.  * by Jarno van der Linden
  26.  * jarno@kcbbs.gen.nz
  27.  *
  28.  */
  29.  
  30. #include <inline/graphics.h>
  31. #include <inline/intuition.h>
  32. #include "glutstuff.h"
  33.  
  34. GLfloat glutGetColor(int ndx, int component)
  35. {
  36.   /* no window */
  37.   if(!glutstuff.curwin || !glutstuff.curwin->context) {
  38.     DEBUGOUT(1, "no window to get colors from\n");
  39.     return (-1.0);
  40.   }
  41.   /* we are in rgb-mode not in index-mode */
  42.   else if(glutGet(GLUT_WINDOW_RGBA)) {
  43.     DEBUGOUT(1, "no index mode\n");
  44.     return (-1.0);
  45.   }
  46.   /* index out of range */
  47.   else if ((ndx < 0) || (ndx > 255)) {
  48.     DEBUGOUT(1, "index out of range\n");
  49.     return (-1.0);
  50.   }
  51.  
  52.   switch (component) {
  53.     case GLUT_RED:
  54.       DEBUGOUT(4, "%g = glutGetColor(%d, %d)\n", ((GLfloat) ((amigaMesaGetOneColor(glutstuff.curwin->context, ndx) >> 16) & 0x000000FF)) / 255, ndx , component);
  55.  
  56.       return ((GLfloat) ((amigaMesaGetOneColor(glutstuff.curwin->context, ndx) >> 16) & 0x000000FF)) / 255;
  57.       break;
  58.     case GLUT_GREEN:
  59.       DEBUGOUT(4, "%g = glutGetColor(%d, %d)\n", ((GLfloat) ((amigaMesaGetOneColor(glutstuff.curwin->context, ndx) >>  8) & 0x000000FF)) / 255, ndx , component);
  60.  
  61.       return ((GLfloat) ((amigaMesaGetOneColor(glutstuff.curwin->context, ndx) >>  8) & 0x000000FF)) / 255;
  62.       break;
  63.     case GLUT_BLUE:
  64.       DEBUGOUT(4, "%g = glutGetColor(%d, %d)\n", ((GLfloat) ((amigaMesaGetOneColor(glutstuff.curwin->context, ndx) >>  0) & 0x000000FF)) / 255, ndx , component);
  65.  
  66.       return ((GLfloat) ((amigaMesaGetOneColor(glutstuff.curwin->context, ndx) >>  0) & 0x000000FF)) / 255;
  67.       break;
  68.     default:    
  69.       return (-1.0);
  70.       break;
  71.   }
  72.  
  73.   return (-1.0);
  74. }
  75.  
  76. #undef    CLAMP
  77. #define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i)))
  78.  
  79. void glutSetColor(int cell, GLfloat red, GLfloat green, GLfloat blue)
  80. {
  81.   DEBUGOUT(4, "glutSetColor(%d, %g, %g, %g)\n", cell, red, green, blue);
  82.  
  83.   if(glutstuff.curwin && glutstuff.curwin->context)
  84.     amigaMesaSetOneColor(glutstuff.curwin->context, cell, CLAMP(red), CLAMP(green), CLAMP(blue));
  85.   else
  86.     DEBUGOUT(1, "no window to set colors to\n");
  87. }
  88.  
  89. void glutCopyColormap(int winnum)
  90. {
  91.   struct GlutWindow *win;
  92.  
  93.   if(glutstuff.curwin && (win = stuffGetWin(winnum))) {
  94.     struct amigamesa_context *this_context, *that_context;
  95.     int cols;
  96.   
  97.     if((this_context = glutstuff.curwin->context) && (that_context = win->context)) {
  98.       for (cols = 256 - 1; cols >= 0; cols--) {
  99.         ULONG color;
  100.  
  101.         color = amigaMesaGetOneColor(that_context, cols);
  102.         amigaMesaSetOneColor(this_context, cols, ((GLfloat) ((color >> 16) & 0x000000FF)) / 255,
  103.                          ((GLfloat) ((color >>  8) & 0x000000FF)) / 255,
  104.                          ((GLfloat) ((color >>  0) & 0x000000FF)) / 255);
  105.       }
  106.  
  107.       return;
  108.     }
  109.  
  110.     DEBUGOUT(1, "incomplete contexts\n");
  111.     return;
  112.   }
  113.  
  114.   DEBUGOUT(1, "cannot find second colormap to copy\n");
  115.   return;
  116. }
  117.